package com.ugoodtech.mdcc.client.dto;


import com.ugoodtech.mdcc.core.Constants;
import com.ugoodtech.mdcc.core.domain.NotificationMessage;
import com.ugoodtech.mdcc.core.utils.BeanUtilEx;

import java.lang.reflect.InvocationTargetException;
import java.text.ParseException;
import java.text.SimpleDateFormat;

/**
 * Copyright © 2013 All Rights Reserved, Ugood Technology, Inc.
 */

public class NotificationMessageResponse {
    private Long messageId;
    private String title;
    private String body;
    private String pushTimeStr;
    private String description;
    private boolean pushed;
    private boolean read = false;
    private boolean circle = false;
    private String pushedStr;
    private String creationTimeStr;

    public Long getMessageId() {
        return messageId;
    }

    public void setMessageId(Long messageId) {
        this.messageId = messageId;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getBody() {
        return body;
    }

    public void setBody(String body) {
        this.body = body;
    }

    public String getPushTimeStr() {
        return pushTimeStr;
    }

    public void setPushTimeStr(String pushTimeStr) {
        this.pushTimeStr = pushTimeStr;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public boolean isPushed() {
        return pushed;
    }

    public void setPushed(boolean pushed) {
        this.pushed = pushed;
    }

    public String getPushedStr() {
        return pushedStr;
    }

    public void setPushedStr(String pushedStr) {
        this.pushedStr = pushedStr;
    }

    public String getCreationTimeStr() {
        return creationTimeStr;
    }

    public void setCreationTimeStr(String creationTimeStr) {
        this.creationTimeStr = creationTimeStr;
    }


    public boolean isCircle() {
        return circle;
    }

    public void setCircle(boolean circle) {
        this.circle = circle;
    }

    public boolean isRead() {
        return read;
    }

    public void setRead(boolean read) {
        this.read = read;
    }

    public static NotificationMessageResponse turnNotificationMessageToResponse(NotificationMessage notificationMessage) throws InvocationTargetException, IllegalAccessException {
        if (null != notificationMessage) {
            SimpleDateFormat defaultFormat = new SimpleDateFormat(Constants.DATE_TIME_FORMAT);
            NotificationMessageResponse notificationMessageResponse = new NotificationMessageResponse();
            BeanUtilEx.copyProperties(notificationMessageResponse, notificationMessage);
            notificationMessageResponse.setMessageId(notificationMessage.getId());
            if (null != notificationMessage.getCreationTime()) {
                notificationMessageResponse.setCreationTimeStr(defaultFormat.format(notificationMessage.getCreationTime()));
            }
            if (null != notificationMessage.getDeliveryTime()) {
                notificationMessageResponse.setPushTimeStr(defaultFormat.format(notificationMessage.getDeliveryTime()));
            }
            if (notificationMessage.isPushed()) {
                notificationMessageResponse.setPushedStr("已推送");
            } else {
                notificationMessageResponse.setPushedStr("未推送");
            }
            if (null == notificationMessage.getPublisher()) {
                notificationMessageResponse.setCircle(true);
            } else {
                notificationMessageResponse.setCircle(false);
            }
            return notificationMessageResponse;
        } else {
            return null;
        }
    }

    public static NotificationMessage turnResponseToNotificationMessage(NotificationMessageResponse notificationMessageResponse) throws ParseException, InvocationTargetException, IllegalAccessException {
        if (null != notificationMessageResponse) {
            SimpleDateFormat defaultFormat = new SimpleDateFormat(Constants.DATE_TIME_FORMAT);
            NotificationMessage notificationMessage = new NotificationMessage();
            BeanUtilEx.copyProperties(notificationMessage, notificationMessageResponse);
            notificationMessage.setId(notificationMessageResponse.getMessageId());
            return notificationMessage;
        } else {
            return null;
        }
    }
}
